﻿using System;
using System.Collections.Generic;
using System.Text;
using MbUnit.Framework;
using MyTestRunner.Domain;
using System.Reflection;
using MyTestRunner.Infrastructure;

namespace MyTestRunner.Tests.Domain
{
    /// <summary>
    /// Specifies how set up methods should be found.
    /// </summary>
    [TestFixture]
    [TestsOn(typeof(ITestFinder))]
    public abstract class WhenFindingSetUpMethods
    {
        /// <summary>
        /// Returns the test finder we want to test.
        /// </summary>
        public abstract ITestFinder CreateSut();

        /// <summary>
        /// Returns a test class that does have a setup method.
        /// </summary>
        public abstract Type GetTestWithSetUpMethod();

        /// <summary>
        /// Returns a test class that does not have a setup method.
        /// </summary>
        public abstract Type GetTestWithoutSetUpMethod();

        /// <summary>
        /// Given that the test does not have a setup method, the method should return false.
        /// </summary>
        [Test]
        public void ShouldReturnFalseWhenTestDoesNotHaveSetUpMethod()
        {
            ITestFinder sut = CreateSut();

            Type testWithoutSetUpMethod = GetTestWithoutSetUpMethod();
            MethodInfo setUpMethod;
            Assert.IsFalse(sut.TryGetSetUpMethod(testWithoutSetUpMethod, out setUpMethod));
            Assert.IsNull(setUpMethod);
        }

        /// <summary>
        /// Given that the test does have a setup method, the method should return true.
        /// </summary>
        [Test]
        public void ShouldReturnTruewhenTestDoesHaveSetUpMethod()
        {
            ITestFinder sut = CreateSut();

            Type testWithSetUpMethod = GetTestWithSetUpMethod();
            MethodInfo setUpMethod;
            Assert.IsTrue(sut.TryGetSetUpMethod(testWithSetUpMethod, out setUpMethod));
            Assert.IsNotNull(setUpMethod);
        }
    }
}
